   .section   .text
   .text
   .align 2
   .global    getchar
   .global    putchar

/*
   32 bit access                          UART
   -------------------------------------------
          case BBUS_in.BADDR(3 downto 0) is
   +00/0 when "00000" => data_tx;
   +04/1 when "00100" => receive_is_ready;
   +0c/3 when "01100" => send_is_ready;
   +10/4 when "10000" => data_rx
 */


uart_base=0x20000000
uart_tx_data=0x00         
uart_rx_data=0x10
uart_tx_is_ready=0x0c     
uart_rx_is_ready=0x04  


# get a character in $2
# uses $8,$9

getchar:	
        la      $8,uart_base
        nop
getchar0:	
        nop
        nop
        nop
        nop
        lw      $9,uart_rx_is_ready($8)
	nop

                /* Branch to address if the variable = 0 */
        beq     $9,$0,getchar0
        nop
        lw      $2,uart_rx_data($8)	    
	nop
        andi    $2,0xff

	j	$31
	nop

# put a character from $2
# uses $8,$12
putchar:	
        la      $8,uart_base
        nop
putchar0:	
        andi    $12,0xff
        nop
        nop
        nop
        nop
        lw 	$12,uart_tx_is_ready($8)	
	nop
                /* Branch to address if the variable = 0 */
        beq     $12,$0,putchar0
	nop

	sw	$4,uart_tx_data($8)
        nop

	j	$31
	nop

